<?php 
defined('IN_TS') or die('Access Denied.'); 

function article(){
/*	
	$arrArticle = aac('article')->findAll('article',array('isaudit'=>0),'addtime desc',null,10);
	foreach($arrArticle as $key=>$item){
		$arrArticle[$key]['title'] = tsTitle($item['title']);
		$arrArticle[$key]['content'] = tsDecode($item['content']);
	}
	
	include template('article','article');
	
}

addAction('home_index_left','article');
*/

	if( $GLOBALS['TS_USER']!=''){
		$mylink = '&link='.$GLOBALS['TS_USER']['userid'];
	}
	global $db;
	//最新文档
	$arrArticles = aac('article')->findAll('article',array(
		'isaudit'=>0,
	),'addtime desc','',5);

	if (count($arrArticles) > 0) {
		$groupids = array_column($arrArticles, "groupid");
		$groups = aac('group')->getGroups($groupids);

		$userids = array_column($arrArticles, "userid");
		$users = aac('user')->getUsers($userids);
	}

	foreach($arrArticles as $key=>$item){
		$arrArticle[] = $item;
		$arrArticle[$key]['title']=tsTitle($item['title']);
		$arrArticle[$key]['user'] = $users[$item["userid"]];
		$arrArticle[$key]['group'] = $groups[$item['groupid']]; 
		$arrArticle[$key]['abs'] = cututf8 ( t(tsDecode($item ['content'])), 0, 80 );
		if(!$arrArticle[$key]['abs']){
			$img_path =getTextPhotos(tsDecode($item ['content']));
			if($img_path){
				$arrArticle[$key]['abs']='<img width="100%" src="'.$img_path[0].'">';
			}
		}
	}

	include template('article','article');

}

function article_css(){

	echo '<link href="'.SITE_URL.'plugins/home/article/style.css" rel="stylesheet" type="text/css" />';

}

addAction('home_index_right','article');
addAction('pub_header_top','article_css');
